<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>会员账户管理页面</title>
<%@ include file="/common/meta.jsp" %>
<%@ include file="/common/import.jsp"%>
<script type="text/javascript">
	$(function(){
		//控制div显示和隐藏
		$('#tab_search').panel({
			iconCls : "icon-search",//图标
			collapsible : true,//是否可折叠面板
			collapsed : true,//是否初始化折叠面板
			title : "查询会员"//标题
		});
		$('#dataCateList').datagrid({
			title:'会员账户管理列表',
			iconCls:'icon-ok',
			url:"${ctx}/admin/member/queryMemberList.action",
			nowrap: false,
			striped: true,
			collapsible:false,				
			fitColumns: true,
			pagination:true,
			singleSelect:true,
			rownumbers:true,
			remoteSort: false,
			pageList:[15,20,30,50],
			idField:'memberId',
			columns:[[
				{field:'memberEname',title:'会员名称',width:50},
				{field:'memberCname',title:'会员全称',width:70},
				{field:'shortName',title:'会员简称',width:45},
				{field:'updateTime',title:'更新时间',width:55},
				{field:'memberType',title:'会员属性',width:30,
					formatter:function(value){
						if( value == '20'){return '个人';}
						else{ return '机构';}
					}
				},
				{field:'memberLevel',title:'会员级别',width:40,
					formatter:function(value){
						if( value == '1'){return '普通会员';}
						else if( value == '2'){return '认证会员';}
						else if( value == '3'){return '正式会员';}
						else{ return '';}
					}
				},
				{field:'op',title:'降级操作',width:60,
					formatter : function(value, rec) {
						var info = "";
						var level = rec.memberLevel;
						if(level == '3'){
							info += "<a href=\"javascript:void(0)\" onclick=\"MemberLevelUpOrDown('"+ rec.memberId+"'"+","+"'down')\" style=\"color: red\" title='会员降级'>降级</a> ";
						}else if(level == '2'){
							info += "<a href=\"javascript:void(0)\" onclick=\"MemberLevelUpOrDown('"+ rec.memberId+"'"+","+"'up')\" style=\"color: green\" title='会员级别恢复'>升级</a> ";
						}
						else{
							info += "-";
						}
						
						return info;
					}
				},
				{field:'opt',title:'运行状态',width:80,
					formatter : function(value, rec) {
						var info = "";
						var s = rec.status;
						if(s == '1'){
							info += "<font color=\"blue\">已启用</font>|<a href=\"javascript:void(0)\" onclick=\"lockOrUnlockMember('"+ rec.memberId+"'"+","+"'lock')\" style=\"color: red\" title='停用该会员'>停用</a> ";
						}else if(s == '0'){
							info += "<font color=\"black\">已停用</font>|<a href=\"javascript:void(0)\" onclick=\"lockOrUnlockMember('"+ rec.memberId+"'"+","+"'unlock')\" style=\"color: green\" title='启用该会员'>启用</a> ";
						}else{
							info += "-";
						}
						return info;
					}
				}
			]],
			toolbar:[{
				text:'刷新',
				iconCls:'icon-reload',
				handler:function(){
					$('#dataCateList').datagrid('reload');
				}
			}
			]
		});		
	});
	//会员启用与停用
	function lockOrUnlockMember(memberId,f){
		var msg = "";
		if("lock" == f){
			msg += '确定要停用该会员账户吗?';
		}else if("unlock" == f){
			msg += '确定要启用该会员账户吗?';
		}
		if(memberId){
			$.messager.confirm('确认',msg,function(flag){  
		        if(flag){  
		            $.ajax({
					  url: "${ctx}/admin/member/lockOrUnlockMember.action?memberId="+memberId+"&flag="+f,
					  type: 'POST',
					  cache: false,
					  success: function(data){
					  	var oTxt = jQuery.parseJSON(data);
					    var mess = oTxt.msg;	
						var flag = oTxt.flag;
				        if(flag=="T"){
							$.messager.alert('提示',mess, 'info',function(){
								reload();
				        	});
						}else{
							$.messager.alert('提示',mess, 'error');
						}
					  }
					});
		        }  
		     });
		  }
	
	}
	
	
	//会员升降级操作
	function MemberLevelUpOrDown(memberId,f){
		var msg = "";
		if("up" == f){
			msg += '确定要升级吗?';
		}else if("down" == f){
			msg += '确定要降级吗?';
		}
		if(memberId){
			$.messager.confirm('确认',msg,function(flag){  
		        if(flag){  
		            $.ajax({
					  url: "${ctx}/admin/member/MemberLevelUpOrDown.action?memberId="+memberId+"&flag="+f,
					  type: 'POST',
					  cache: false,
					  success: function(data){
					  	var oTxt = jQuery.parseJSON(data);
					    var mess = oTxt.msg;	
						var flag = oTxt.flag;
				        if(flag=="T"){
							$.messager.alert('提示',mess, 'info',function(){
								reload();
				        	});
						}else{
							$.messager.alert('提示',mess, 'error');
						}
					  }
					});
		        }  
		     });
		  }
		
	}
	// 查找
	function searchCate(){
        var queryParams = $('#dataCateList').datagrid('options').queryParams;	    
       	var opt = $('#dataCateList').datagrid('options'); 
        $('#dataCateList').datagrid('options').pageNumber=1;
        queryParams["memberEname"] = $('#memberEname').val();
		queryParams["memberCname"] = $('#memberCname').val();
        $('#dataCateList').datagrid('reload');
        
        var page = $('#dataCateList').datagrid('getPager');
		page.pagination({pageNumber:1,pageSize:opt.pageSize});
	}
	
	 //清除查询
	 function clearSearch(){					
	    $('#memberEname').val('');
	    $('#memberCname').val('');
	 }
	 
	//重新加载数据
	function reload() {
		$('#dataCateList').datagrid('reload');
	}
	</script>

  </head>
  
  <body>

	<!-- 查询窗口 -->
  	 	<div id="tab_search">

		<table class="datagrid-body" >
			<tr>	
				<td class="datagrid-header">会员名称：</td>
				<td><input type="text" id="memberEname" name="memberEname" size="30" value="" /></td>
			</tr>
			
			<tr >
				<td class="datagrid-header">会员全称：</td>
				<td><input type="text" id="memberCname" name="memberCname" size="30" value="" /></td>
			</tr>

		
			<tr>	
				<td class="datagrid-header"></td>
				<td>
					<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-search" onClick="searchCate();">查找</a>
					&nbsp;&nbsp;
					<a class="easyui-linkbutton" iconCls="icon-redo" href="javascript:void(0)" onclick="clearSearch();">清空</a>
				</td>	
			</tr>
		</table>

	</div>
    
     <table id="dataCateList"></table>

  </body>
</html>
